<?php
	include_once dirname(dirname(dirname(__FILE__))).'/inc/bootConfig.php';
	include_once '../checkLogin.php';
	$mid = getRequest('mid');
	if(isset($_POST['edit_content'])){
		$upd['c_mid'] = $mid = getRequest('mid');
		$dir = "../../zjx/Runtime/Cache/selectModel/";
		if(!Module_Select::checkMidInContent($mid)){
			$upd['c_content'] = addslashes(sy2dy($_REQUEST['modcontent']));
			if($upd['c_content'] == '<br />'){
				jstop('内容不能为空');
			}
			$upd['c_time'] = date('Y-m-d H:i:s');
			$upd['c_user'] = $_SESSION['username'];
			$tablename = 'zjx_content';
			if(Module_Edit::insert($tablename,$upd)){
				Cache_Filecache::delFileCache($dir);
				jstop('添加成功');
			}
			jstop('系统繁忙，请重试');
		}else{
			$upd['c_content'] = addslashes(sy2dy($_REQUEST['modcontent']));
			if($upd['c_content'] == '<br />'){
				jstop('内容不能为空');
			}
			$upd['c_time'] = date('Y-m-d H:i:s');
			$upd['c_user'] = $_SESSION['username'];
			$tablename = 'zjx_content';
			if(Module_Edit::update($tablename,$upd,'c_mid='.$mid)){
				Cache_Filecache::delFileCache($dir);
				jstop('修改成功');
			}
			jstop('系统繁忙，请重试');
		}
	}
	
	$allContentMod = Module_Select::getContentModInfoByUrl('content');
	if(!empty($mid)){
		$modcon = Module_Select::selectModconById($mid);
	}
	
	$haveConMid = Module_Select::getHaveConMid();
//	var_dump($haveConMid);
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>查看模块</title>
<link rel="stylesheet" type='text/css' href='../Public/static/css/admincp/admincp.css'>
</head>
<body>
<form action="" method="post">
<input type="hidden" name="modid" value="<?php echo $mid?>"/>
<table id="tips" class="tb tb2 ">
	<tbody>
		<tr>
			<th class="partition" colspan='2'>技巧提示</th>
		</tr>
		<tr>
			<td class="tipsblock" colspan='2'>
			<ul id="tipslis">
				<li>请先选择相应的模块，然后修改或添加内容</li>
				<li>文本框中的内容如果是复制进来的，最好先清除所有格式之后再进行编辑</li>
			</ul>
			</td>
		</tr>
	</tbody>
	<tbody>
	<?php if(empty($mid)){?>
		<tr>
			<td>请选择需要添加内容的模块
				<select name='mid'>
				<?php 
					foreach ($allContentMod as $v){
						if(in_array($v['z_id'],$haveConMid))continue;
				
				?>
					<option value="<?php echo $v['z_id']?>"><?php echo $v['z_name']?></option>
				<?php }?>
				</select>
			</td>
		</tr>
		<?php }?>
		<tr><td>
			<INPUT id=content style="DISPLAY: none" type=hidden name="modcontent" value="<? echo htmlspecialchars($modcon['c_content']) ?>">
			<INPUT id=content___Config style="DISPLAY: none" type=hidden> 
			<IFRAME id=content___Frame src="../Public/static/FCK/editor/fckeditor.html?InstanceName=modcontent&Toolbar=Default" frameBorder=0 width=70% scrolling=no height=400> 
			</IFRAME>
		</td></tr>
		<tr>
			<td>
				<input type='submit' class="btn" name='edit_content' value="保存" />
				<input type='button' class="btn look_con" name='look_content' value="预览" />
			</td>
		</tr>
	</tbody>
</table>
</form>
</body>
</html>
<script type="text/javascript" src="../Public/static/js/jquery.js"></script>
<script type="text/javascript">
function runCode(url,content)  //定义一个运行代码的函数，
{
 // var code=event.srcElement.parentElement.children[0].value;//即要运行的代码。
  var newwin=window.open(url);  //打开一个窗口并赋给变量newwin。
  newwin.opener = null // 防止代码对论谈页面修改
  newwin.document.write(content);  //向这个打开的窗口中写入代码code，这样就实现了运行代码功能。
  newwin.document.close();

}
$('input.look_con').click(function(){
	var conname = FCKeditorAPI.GetInstance('modcontent')
	var con = conname.EditorDocument.body.innerHTML 
	var url = "/www/content/index/modid/"+$('input[name="modid"]').val()
	runCode(url,con)
//	window.open("/www/content/index/modid/"+$('input[name="modid"]').val()+"/content/"+escape(con))	
})
</script>